package cm.unit2.theme2;

import java.util.Arrays;
import java.util.Objects;

public class Equals {

	private Integer id;
	private int[] array;
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Arrays.hashCode(array);
		result = prime * result + Objects.hash(id);
		return result;
	}



	@Override
	public boolean equals(Object obj) {
		// 比较地址
		if (this == obj) {
			return true;
		}
		// 实例判断
		if (!(obj instanceof Equals)) {
			return false;
		}
		// 比较各个字段
		Equals other = (Equals) obj;
		// 使用工具类提供的静态方法
		return Arrays.equals(array, other.array) 
				&& ((this == obj) || (this.equals(obj)));
	}



	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Equals obj01 = new Equals();
		Equals obj02 = new Equals();
		Equals obj03 = obj01;
		System.out.println(obj01 == obj02);
		System.out.println(obj01 == obj03);

	}

}
